import {
  Body,
  Controller,
  Get,
  Post,
  UsePipes,
  ValidationPipe,
} from '@nestjs/common';
import { Res } from './dbo/res.dbo';
import { TelegramService } from './telegram.service';

@Controller('telegram')
export class TelegramController {
  constructor(private readonly tgService: TelegramService) {}

  @UsePipes(ValidationPipe)
  @Post('/')
  getUpdate(@Body() res: Res) {
    
    if (res.message?.reply_to_message?.is_topic_message) {
      if (res.message.text) {
        if (res.message.text.length !== 0)
          this.tgService.MessageHandler(
            res.message.chat.id,
            res.message.text,
            res.message.message_thread_id,
          );
      }
    }
  }
}
